<template>
    <div class="mainIndex">
        <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/index' }">搜索查询支付信息</el-breadcrumb-item>
        </el-breadcrumb>
        <el-row class="condition-search">
            <div class="demo-input-suffix-1">
                <div class="fix-div">
                    <mark>姓名</mark>
                    <input size="mini" prefix-icon="el-icon-search" v-model="searchName.name" />
                    <mark>学号</mark>
                    <input size="mini" prefix-icon="el-icon-search" v-model="searchName.notice_num" />
                    <mark>身份证</mark>
                    <input size="mini" prefix-icon="el-icon-search" v-model="searchName.id_card" />
                    <mark>支付状态</mark>
                    <select name="" id="" v-model="searchName.state">
                        <option value="1">支付成功</option>
                        <option value="0">未支付</option>
                    </select>
                  <mark>年级</mark>
                  <select name="" id="" v-model="searchName.grade">
                    <option value="2019">2019年级</option>
                    <option value="2020">2020年级</option>
                  </select>
                  <mark>专业年限</mark>
                  <select name="" id="" v-model="searchName.professionales_id">
                    <option value="">请选择</option>
                    <option value="3">本科(四年制)</option>
                    <option value="4">专科(三年制)</option>
                    <option value="5">专升本(二年制)</option>
                  </select>

                    <mark>收费人</mark>
                    <select name="" id="" v-model="searchName.admin_users_id">

                        <option v-for="(v,k) in chargeUsers" :key="k" :value="v.id">{{v.username}}</option>
                    </select>
                    <mark>时间</mark>
                    <el-date-picker v-model="datetimes" size="small" type="datetimerange" align="right" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:01:00', '23:59:00']" @change="dateTime"></el-date-picker>
                    <el-button class="fix-btn" type="primary" size="mini" icon="el-icon-search" @keyup.enter="Sous" @click="Sous">搜索</el-button>
                </div>
            </div>
            <div class="demo-input-suffix-2">
                <p style="display: inline-block;font-size: 15px;padding-right: 10px;">总人数：{{pageInfo.pageTotal}}人</p>
                <p style="display: inline-block;font-size: 15px;padding-right: 10px;">总金额：{{respData.sum}}元</p>
                <el-button type="warning" size="mini" icon="el-icon-download" @click="exportExcel">导出数据</el-button>
                <el-button style="margin-top:3px;" type="warning" size="mini" icon="el-icon-download" @click="classexportExcel">分类导出</el-button>
            </div>
        </el-row>
        <el-table id="exportTab" :data="respDataList" v-loading="listLoading" border stripe style="width: 100%;color:#000000;" @selection-change="handleSelectionChange">
            <el-table-column prop="id" type="selection" label="全选" align="center"></el-table-column>
            <el-table-column prop="username" label="姓名" align="center"></el-table-column>
            <el-table-column prop="phone" label="手机号" align="center"></el-table-column>
            <el-table-column prop="notice_number" label="学号" align="center"></el-table-column>
            <el-table-column prop="courtyard_department" label="院系" align="center"></el-table-column>
            <el-table-column prop="professional" label="专业" align="center"></el-table-column>
            <el-table-column prop="grade" label="年级" align="center"></el-table-column>
            <el-table-column prop="professionalesId" label="专业年限" align="center"></el-table-column>
            <el-table-column prop="amount_real" label="应收费金额" align="center"></el-table-column>
            <el-table-column prop="pay_success_time" label="收费时间" align="center"></el-table-column>
            <el-table-column prop="admin_user" label="收费人员" align="center"></el-table-column>
            <el-table-column prop="state" label="状态" align="center">
                <template slot-scope="scope">{{scope.row.state == 0 ? '未支付' : scope.row.state == 1 ? '支付成功' : scope.row.state == 2 ? '支付失败' : scope.row.state == '3' ? '取消支付' : ''}}</template>
            </el-table-column>
            <el-table-column label="操作" align="center" fixed="right" min-width="118px">
                <template slot-scope="scope">
                    <el-button size="mini" plain @click="handleEdit(scope.$index, scope.row)" style="color: #000000;">编辑</el-button>
                    <el-button size="mini" plain @click="handleDetail(scope.$index, scope.row)" style="color: #000000;">详情</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination background layout="prev, pager, next, jumper, total" :current-page="pageInfo.currentPage" :page-size="pageInfo.pageSize" :total="pageInfo.pageTotal" @current-change="handleCurrentChange"></el-pagination>
        <el-dialog custom-class="customClass"  title="分类导出" :visible.sync="dialogVisible" width="539px">
            <span>时间</span>
            <el-date-picker v-model="exportExcelData.time" size="small" type="datetimerange" align="right" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:01:00', '23:59:00']" @change="dateTimeY"></el-date-picker>
            <el-select v-model="exportExcelData.category_id" placeholder="项目名称">
                <el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id"></el-option>
            </el-select>
            <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="classexportExcelData">导出</el-button>
          </span>
        </el-dialog>
    </div>
</template>

<script>
    import apis from '../apis/apis';
    import FileSaver from 'file-saver';
    import XLSX from 'xlsx';
    export default {
        data() {
            return {
                inputVal: '',
                listLoading: false,
                dialogVisible: false,
                respData: {},
                respDataList: [],
                chargeUsers: [],
                datetimes: '',
                pageInfo: {
                    currentPage: 1,
                    pageSize: 20,
                    pageTotal: 1
                }, //分页
                formSearch: {
                    name: '',
                    city: '',
                    type: null,
                    age: '',
                    gender: null,
                    qq: '',
                    startdate: null,
                    enddate: null
                }, //表单查询
                formEdit: {
                    id: null,
                    name: '',
                    city: '',
                    type: '',
                    age: '',
                    gender: null,
                    qq: ''
                }, //表单编辑
                searchName: {
                    name: '',
                    id_card: '',
                    notice_num: '',
                    star_time: '',
                    end_time: '',
                    state: this.$route.query.status ? this.$route.query.status : '',
                    admin_users_id: '',
                    pageSize: 20,
                    page: 1,
                    grade:'2020',
                    professionales_id:'',
                },
                exportExcelData: {
                    category_id: '',
                    time: '',
                    startTime: '',
                    endTime: ''
                },
                options: [],
            }
        },
        // 无dom操作的放在这里请求
        created() {
            this.getchargeUsersList();
            if(this.$route.query.status) {
                this.Sous()
            }
        },
        mounted() {
            var self = this;
            self.getPayment(self.searchName);
        },
        methods: {
            /* 点击选择 */
            handleSelectionChange(val) {
                console.info(val);
            },
            /** 分页切换 */
            handleCurrentChange(val) {
                var self = this;
                self.pageInfo.currentPage = val;
                self.searchName.page = val;
                self.getPayment(self.searchName);
            },
            /** 打开详情页 */
            openDetail(row) {
                this.$common.OpenNewPage(this, 'detail', row);
            },
            /* 日期时间改变 */
            dateTime() {
                var self = this;
                self.searchName.star_time = +(self.datetimes[0].getTime() / 1000);
                self.searchName.end_time = +(self.datetimes[1].getTime() / 1000);
                console.log(self.datetimes[0].getTime() / 1000);
                console.log(self.datetimes[1].getTime() / 1000);
                console.log(self.searchName);
            },
            dateTimeY() {
                var self = this;
                self.exportExcelData.startTime = +(self.exportExcelData.time[0].getTime() / 1000);
                self.exportExcelData.endTime = +(self.exportExcelData.time[1].getTime() / 1000);
                console.log(self.exportExcelData);
            },
            /* 获取收费人员*/
            getchargeUsersList() {
                var self = this;
                apis.contApi.getchargeUsersList().then((res) => {
                    if(res.data.code == 0) {
                        self.chargeUsers = res.data.data;
                    }
                }).catch((error) => {
                    console.error(error);
                });
            },
            /* 获取列表页*/
            getPayment(search) {
                var self = this;
                if(search.is_export) {
                    delete search.is_export;
                }
                apis.contApi.paymentlist(search).then((res) => {
                    if(res.data.code == 0) {
                        self.respData = res.data.data;
                        self.pageInfo.pageTotal = self.respData.count;
                        self.respDataList = self.respData.list;
                    }
                }).catch((error) => {
                    console.error(error);
                });
            },
            /* 搜索 */
            Sous() {
                var self = this;
                self.pageInfo.currentPage = self.searchName.page = 1;
                self.getPayment(self.searchName);
                const loading = this.$loading({
                    lock: true,
                    text: '正在加载数据…',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });
                setTimeout(() => {
                    loading.close();
                }, 2000);
            },
            /** 打开详情页 */
            handleDetail(index, rowData) {
                var self = this;
                var params = {
                    id: rowData.id
                };
                apis.contApi.paymentdetail(params).then((res) => {
                    self.$store.state.payment = false;
                    self.$store.state.isPard = res.data.data.charge.state;
                    this.$store.commit('changePayment', res.data.data);
                    self.$router.push({
                        path: '/paymentDetail',
                        query: {
                            status: self.searchName.state
                        }
                    });
                }).catch((error) => {
                    console.error(error);
                });
            },
            /** 打开编辑弹窗 */
            handleEdit(index, rowData) {
                var self = this;
                var params = {
                    id: rowData.id
                };
                apis.contApi.paymentdetail(params).then((data) => {
                    self.$store.state.payment = true;
                    self.$store.state.isPard = data.data.data.charge.state;
                    this.$store.commit('changePayment', data.data.data);
                    self.$router.push({
                        path: '/paymentDetail',
                        query: {
                            status: self.searchName.state
                        }
                    });
                }).catch((error) => {
                    console.error(error);
                });
            },
            /** 删除 */
            handleDelete(index, rowData) {
                var self = this;
                var params = {
                    id: rowData.id
                };
                apis.contApi.delepayment(params).then((data) => {
                    console.info(data.data);
                }).catch((error) => {
                    console.error(error);
                });
            },
            /* url转换*/
            convertObj(data) {
                var _result = [];
                for(var key in data) {
                    var value = data[key];
                    if(value.constructor == Array) {
                        value.forEach(function(_value) {
                            _result.push(key + "=" + _value);
                        });
                    } else {
                        _result.push(key + '=' + value);
                    }
                }
                return _result.join('&');
            },
            /* 导出excel */
            exportExcel() {
                var self = this;
                let exportData = self.searchName;
                exportData.pageSize = self.pageInfo.pageTotal;
                exportData.is_export = 1;
                if(exportData.name || exportData.id_card || exportData.notice_num || exportData.state || exportData.admin_users_id || exportData.star_time || exportData.end_time) {
                    if(!exportData.name) delete exportData.name;
                    if(!exportData.id_card) delete exportData.id_card;
                    if(!exportData.notice_num) delete exportData.notice_num;
                    if(!exportData.state) delete exportData.state;
                    if(!exportData.admin_users_id) delete exportData.admin_users_id;
                    if(!exportData.star_time) delete exportData.star_time;
                    if(!exportData.end_time) delete exportData.end_time;
                }
                let urls = this.GLOBAL.baseURL + 'admin/charge?' + self.convertObj(exportData);
                window.open(urls, "_blank")
            },
            // 分类导出
            classexportExcel() {
                var self = this;
                self.dialogVisible = true;
                apis.contApi.getProfessList().then((res) => {
                    console.info(res);
                    self.options = res.data.data.chargingItems;
                }).catch((err) => {
                    console.error(err)
                });
            },
            classexportExcelData() {
                var self = this;
                console.info(self.exportExcelData);
                var params = {
                    is_export: 1,
                    category_id: self.exportExcelData.category_id,
                    start_time: self.exportExcelData.startTime,
                    end_time: self.exportExcelData.endTime
                }
                if(!params.category_id || !params.start_time || !params.end_time) {
                    this.$message('请选择导出条件');
                    return false;
                }
                let urls = this.GLOBAL.baseURL + 'admin/charge/exportChargeCategories?' + self.convertObj(params);
                // debugger
                window.open(urls, "_blank")
            },
            formatJson(filterVal, jsonData) {
                return jsonData.map(v => filterVal.map(j => v[j]))
            }
        }
    }
</script>

<style scoped="scoped">
    mark {
        background: transparent;
    }

    .hongbao_zanzhu {
        display: block;
        position: fixed;
        text-align: center;
        bottom: 336px;
        width: 230px;
        right: 0;
        font-size: 23px;
        color: #505458;
    }

    .hongbao {
        position: fixed;
        bottom: 0;
        right: 0;
        height: 330px;
        width: 230px;
    }

    .content_inner .el-table th>.cell {
        display: inline-flex;
        justify-content: center;
        align-items: center;
        cursor: pointer;
    }

    .content_inner .el-table th>.cell .el-dropdown {
        width: 100%;
    }

    .content_inner .el-table th>.cell .el-dropdown span.el-dropdown-link.el-dropdown-selfdefine {
        width: 100%;
    }

    .el-dropdown-menu.el-popper {
        width: 180px;
    }

    .el-breadcrumb {
        padding: 5px 0 0px;
    }

    .el-pagination {
        margin: 20px 0 10px;
        text-align: right;
    }
    /* 条件筛选*/

    .condition-search {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin: 10px 0;
        height: 66px;
        width: 100%;
        text-align: left;
    }

    .condition-search>.demo-input-suffix {}

    .condition-search>.demo-input-suffix-1 {
        position: absolute;
        left: 0;
        width: calc(100% - 368px);
        font-size: 15px;
    }

    .condition-search>.demo-input-suffix-1 mark {
        min-width: 45px;
        line-height: 32px;
        padding: 0 5px;
        text-align: left;
    }

    .condition-search>.demo-input-suffix-1 input,
    .condition-search>.demo-input-suffix-1 select {
        width: 115px;
        height: 30px;
        margin: 0;
        text-indent: 5px;
        color: #00d1b2;
        outline: none;
        border: none;
        border-radius: 3px;
        box-shadow: inset 0 0 0 1px #00d1b2;
    }

    .condition-search>.demo-input-suffix-1 input::-webkit-input-placeholder {
        color: #00d1b2;
    }

    .condition-search>.demo-input-suffix-1 button,
    .condition-search>.demo-input-suffix-2 button {
        height: 30px;
        margin: 0;
    }

    .condition-search>.demo-input-suffix-1 input.el-input__inner {
        border-radius: 3px 0 0 3px;
    }

    .condition-search>.demo-input-suffix-2 {
        position: absolute;
        right: 0;
        width: 368px;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        flex-wrap: wrap;
    }

    .el-range-editor.el-input__inner,
    .el-range-editor.is-active,
    .el-range-editor.is-active:hover {
        width: 350px;
        height: 30px;
        margin-right: 5px;
        text-indent: 5px;
        color: #00d1b2;
        outline: none;
        border: none;
        border-radius: 3px;
        box-shadow: inset 0 0 0 1px #00d1b2;
    }
</style>
